﻿using Moq;
using NUnit.Framework;
using Safal.IncidentTracker.Domain.Abstract;
using Safal.IncidentTracker.Domain.Entities;
using Safal.IncidentTracker.WebUI.Controllers;
using Safal.IncidentTracker.WebUI.HtmlHelpers;

namespace Safal.IncidentTracker.Tests
{
    [TestFixture]
    public class ViewIncidents
    {
        [Test]
        public void Can_Create_IncidentsController()
        {
            var controller = new IncidentsController(null);

            Assert.That(controller, Is.Not.Null);
        }
        [Test]
        public void Can_View_A_List_Of_Incidents()
        {
            // Arrange
            Mock<IIncidentsRepository> repository = UnitTestHelpers.MockIncidentsRepository(
                    new Incident { Id = 1, Title = "Fix Machine #1", },
                    new Incident { Id = 2, Title = "Fix Machine #2", }
                );
            var controller = new IncidentsController(repository.Object) {PageSize = 2};

            // Act
            var result = controller.List();

            // Assert
            var viewModel = (PagedList<Incident>)result.ViewData.Model;
            Assert.That(viewModel.TotalCount, Is.EqualTo(2));
            Assert.That(viewModel[0].Title, Is.EqualTo("Fix Machine #1"));
            Assert.That(viewModel[1].Title, Is.EqualTo("Fix Machine #2"));
            


        }
        [Test]
        public void Can_View_A_Single_Page_Of_Incidents() {
            // Arrange
            Mock<IIncidentsRepository> repository = UnitTestHelpers.MockIncidentsRepository(
                    new Incident { Id = 1, Title = "Fix Machine #1",  },
                    new Incident { Id = 2, Title = "Fix Machine #2",  }
                );
            var controller = new IncidentsController(repository.Object) { PageSize = 2 };
            controller.PageSize = 1;

            // Act
            var result = controller.List(2);

            var viewModel = (PagedList<Incident>)result.ViewData.Model;
            Assert.That(viewModel.Count, Is.EqualTo(1));
            Assert.That(viewModel[0].Title, Is.EqualTo("Fix Machine #2"));
            

        }
      

    }
}
